package com.graduation.mathematics;

import android.os.Handler;
import android.os.Looper;
import android.view.View;

import com.graduation.mathematics.base.BaseApplication;
import com.graduation.mathematics.bean.FunnyExam;
import com.graduation.mathematics.bean.Ranking;
import com.graduation.mathematics.bean.UserInfo;
import com.graduation.mathematics.db.BaseDBHelper;

import org.litepal.LitePal;
import org.litepal.LitePalDB;

public class IApplication extends BaseApplication {
    private static IApplication applicationContext;
    private static Handler handler;

    @Override
    public void onCreate() {
        super.onCreate();
        initDB();
    }

    public static IApplication getInstance() {
        return applicationContext;
    }

    public static Handler getHandler() {
        if (null == handler)
            handler = new Handler(Looper.getMainLooper());
        return handler;
    }
    private void initDB(){
        LitePal.initialize(this);

        LitePalDB litePalDB = new LitePalDB("mathematics", 3);
        litePalDB.addClassName(FunnyExam.class.getName());
        litePalDB.addClassName(UserInfo.class.getName());
        litePalDB.addClassName(Ranking.class.getName());

        LitePal.use(litePalDB);

        //初始化数据
        if (BaseDBHelper.getInstance().isFirstInit()) {
            //初始化题库数据
            BaseDBHelper.getInstance().initFunnyExam(this);
        }
    }
}
